{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 卷积神经网络之高维的神经元\n",
    "- 对于一般的神经元,张量的形式为B * 4,其中B表示数据量,4表示神经元个数.\n",
    "- 对于卷积神经网络,张量形式为 B * 3 * 4 * 4 其中,B表示数据量,3表示通道数,4,4表示图像的长和高\n",
    "对于一般的神经网络,层与层之间的联系主要包含两种运算\n",
    "1. 线性运算\n",
    "2. 激活函数\n",
    "而对于卷积神经网络,层与层之间的联系主要包含两种运算\n",
    "1. 卷积运算\n",
    "2. 池化操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\Users\\MECHREVO\\anaconda3\\Lib\\site-packages\\torch\\utils\\_pytree.py:185: FutureWarning: optree is installed but the version is too old to support PyTorch Dynamo in C++ pytree. C++ pytree support is disabled. Please consider upgrading optree using `python3 -m pip install --upgrade 'optree>=0.13.0'`.\n",
      "  warnings.warn(\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "import torch.nn as nn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def conv_example(in_channel,kernel):\n",
    "    output = torch.zeros(24,24)\n",
    "    for h in range(24):\n",
    "        for w in range(24):\n",
    "            inputs = in_channel[h:h+5,w:w+5]\n",
    "            output[h,w] = (inputs * kernel).sum()\n",
    "    return output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "m = nn.Conv2d(1,1,(5,5),bias=False)\n",
    "x = torch.randn(1,1,28,28) # 第一个1表示数据量,第二行1表示通道为1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "nvgpu",
   "language": "python",
   "name": "nvgpu"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
